package mumu.android.animate.property;

import mumu.android.R;
import android.animation.ObjectAnimator;
import android.animation.PropertyValuesHolder;
import android.animation.ValueAnimator;
import android.annotation.TargetApi;
import android.app.Activity;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;

/**
 * 透明度
 * 
 * @author Administrator
 * 
 */
public class frame extends Activity {

	Button btn_1;
	ImageView img;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);

		setContentView(R.layout.animate);
		img = (ImageView) findViewById(R.id.img_1);
		btn_1 = (Button) findViewById(R.id.btn_1);
		img.setImageResource(R.drawable.ic_launcher);

		// Keyframe kf0 = Keyframe.ofInt(0, 400);
		// Keyframe kf1 = Keyframe.ofInt(0.25f, 200);
		// Keyframe kf2 = Keyframe.ofInt(0.5f, 400);
		// Keyframe kf4 = Keyframe.ofInt(0.75f, 100);
		// Keyframe kf3 = Keyframe.ofInt(1f, 500);
		// PropertyValuesHolder pvhRotation =
		// PropertyValuesHolder.ofKeyframe("width", kf0, kf1, kf2, kf4, kf3);
		// ObjectAnimator oa = ObjectAnimator.ofPropertyValuesHolder(img,
		// pvhRotation);
		// oa.setDuration(2000);
		// oa.start();

		btn_1.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// ObjectAnimator oa = ObjectAnimator.ofInt(img, "translationX",
				// 400, 200, 400, 100, 500);
				// oa.setDuration(2000);
				// oa.start();

				PropertyValuesHolder pvhTrans = PropertyValuesHolder.ofFloat("x", 0, 220, 100);
				PropertyValuesHolder pvhTransY = PropertyValuesHolder.ofFloat("y", 0, 220, 100);
				PropertyValuesHolder pvhRotate = PropertyValuesHolder.ofFloat("Rotation", 0, 180);
				ObjectAnimator oa = ObjectAnimator.ofPropertyValuesHolder(img, pvhRotate, pvhTrans, pvhTransY);
				oa.setDuration(1000);
				oa.start();
				
				animateWobbleInverse(btn_1);
			}
		});
	}

	private void animateWobbleInverse(View v) {
		ObjectAnimator animator = createBaseWobble(v);
		animator.setFloatValues(2, -2);
		animator.start();
	}

	private ObjectAnimator createBaseWobble(View v) {
		ObjectAnimator animator = new ObjectAnimator();
		animator.setDuration(180);
		animator.setRepeatMode(ValueAnimator.REVERSE);
		animator.setRepeatCount(ValueAnimator.INFINITE);
		animator.setPropertyName("rotation");
		animator.setTarget(v);
		return animator;
	}
}
